#!/bin/bash

echo "=== 协议性能对比测试 ==="

# 设置测试参数
N=6
BATCH_SIZE=5000
TX_SIZE=250

echo "测试参数: N=$N, batchsize=$BATCH_SIZE, tx_size=$TX_SIZE"

# 清理端口
echo "清理端口..."
pkill -f ebbflow_server
pkill -f ebbflow_client
pkill -f waterbear_server
pkill -f waterbear_client
pkill -f turritopsis
sleep 2

echo "=== 测试1: EbbFlow性能 ==="
cd /home/ebbflow
echo "构建EbbFlow..."
make build

echo "启动EbbFlow服务器..."
for i in $(seq 0 $((N-1))); do
    ./bin/ebbflow_server -id $i -n $N -f $((N/3)) &
    sleep 1
done

echo "等待服务器启动..."
sleep 5

echo "启动EbbFlow客户端..."
./bin/ebbflow_client -batch $BATCH_SIZE -txsize $TX_SIZE -count 1000 &
sleep 10

echo "停止EbbFlow..."
pkill -f ebbflow_server
pkill -f ebbflow_client
sleep 2

echo "=== 测试2: WaterBear性能 ==="
cd /home/waterbear
echo "构建WaterBear..."
make build

echo "启动WaterBear服务器..."
for i in $(seq 0 $((N-1))); do
    ./bin/waterbear_server -id $i -n $N -f $((N/3)) &
    sleep 1
done

echo "等待服务器启动..."
sleep 5

echo "启动WaterBear客户端..."
./bin/waterbear_client -batch $BATCH_SIZE -txsize $TX_SIZE -count 1000 &
sleep 10

echo "停止WaterBear..."
pkill -f waterbear_server
pkill -f waterbear_client
sleep 2

echo "=== 测试3: Turritopsis性能 ==="
cd /home/Turritopsis
echo "构建Turritopsis..."
make build

echo "启动Turritopsis服务器..."
for i in $(seq 0 $((N-1))); do
    ./bin/turritopsis_server -id $i -n $N -f $((N/3)) &
    sleep 1
done

echo "等待服务器启动..."
sleep 5

echo "启动Turritopsis客户端..."
./bin/turritopsis_client -batch $BATCH_SIZE -txsize $TX_SIZE -count 1000 &
sleep 10

echo "停止Turritopsis..."
pkill -f turritopsis_server
pkill -f turritopsis_client

echo "=== 协议性能对比测试完成 ==="
